package com.yqg.manage.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yqg.manage.common.Result;

import com.yqg.manage.service.IFrontFiveBagsService;
import com.yqg.manage.entity.FrontFiveBags;

import org.springframework.web.bind.annotation.RestController;

/**
 * FrontFiveBagsController 前端控制器
 *
 * @author zxf
 * @since 2025-08-06
 */
@RestController
@RequestMapping("/front-five-bags")
public class FrontFiveBagsController {

    @Resource
    private IFrontFiveBagsService frontFiveBagsService;

    /**
     * 新增或者更新
     */
    @PostMapping("/edit")
    public Result save(@RequestBody FrontFiveBags frontFiveBags) {
        return Result.success(frontFiveBagsService.saveOrUpdate(frontFiveBags));
    }

    /**
     * 删除
     */
    @GetMapping("delete/{id}")
    public Result delete(@PathVariable Integer id) {
        FrontFiveBags frontFiveBags = frontFiveBagsService.getById(id);
        return Result.success(frontFiveBagsService.saveOrUpdate(frontFiveBags));
    }

    /**
     * 查询所有
     */
    @GetMapping("/all")
    public Result findAll() {
        QueryWrapper<FrontFiveBags> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", "0");
        List<FrontFiveBags> list = frontFiveBagsService.list(queryWrapper);
        return Result.success(list);
    }

    /**
     * 根据id查询
     */
    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        return Result.success(frontFiveBagsService.getById(id));
    }

    /**
     * 分页查询
     */
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize,
                           @RequestParam(required = false) String status,
                           @RequestParam(required = false) String name) {
        return Result.success( frontFiveBagsService.pageList(pageNum,pageSize,status,name));
    }

}

